from worker import Worker
from numpy import *
from matplotlib.pyplot import *

class Question4(Worker): #Subclasses Worker
    def __init__(self,framework): #gets passed the framework when created
        Worker.__init__(self,framework)
        self.title = 'Question 4'

    def get_result(self):
        ds = self.framework.large_dataset
        head = self.framework.large_header
        ratings = [[] for i in range(14)]
        metas = [[] for i in range(14)]
        for row in ds:
            for i,rating in zip(range(14),row[11:25]):
                if rating!='':
                    ratings[i].append(float(rating))
                    metas[i].append(float(row[25]))
        sources = head[11:25]
        corrs = []
        for rating,meta in zip(ratings,metas):
            corrs.append(corrcoef([array(meta),array(rating)])[0][1])
        
        fig = gcf() #get current figure
        bar(range(len(sources)),corrs)
        title('Correlation Between Publication Review and Metascore')
        xlabel('Publication')
        ylabel('Correlation Coefficient with Metascore')
        #TODO: still need to figure out how to label each bar
        return ('This graph shows correlation blah blah',fig)